package com.sh.listener;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;

import com.sh.tcp.SmartServer;

/**
* @comments
* @author  zg
* @date 2018年4月7日
*/
public class SmartServerStartupListener implements ApplicationListener<ContextRefreshedEvent>{
	private Logger logger = LogManager.getLogger(this.getClass());
	
	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		ApplicationContext context = event.getApplicationContext();
		Environment env = context.getEnvironment();
		String socketPort = env.getProperty("smartServer.port");
		SmartServer server = new SmartServer(Integer.valueOf(socketPort));
		try {
			server.start();
		} catch (Exception e) {
			logger.error("SmartServer启动异常：", e);
		}
	}

}
